package com.zprmb.udzt;

import org.json.JSONObject;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zprmb.udzt.util.Constant;
import com.zprmb.udzt.util.VolleryUtil;

public class Register_Success extends BaseActivity implements OnClickListener{
	private String tiyan_money,red_money,resume_real_name,registerType;
	private TextView img_tiyan,tv_real_name,tv_red_money;
	private ImageView img_back;
	private Button btn_inassest;
	private TextView tv_getting_ground;
	private int who=0;
	private RelativeLayout rl_back;
	
	@Override 
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.regist_success);
		BbtApplication.getInstance().addActvity(this);
		tiyan_money=getIntent().getStringExtra("tiyan");
//		 red_money=getIntent().getStringExtra("red");
//		resume_real_name=getIntent().getStringExtra("resume");
//		registerType=getIntent().getStringExtra("registerType");
		img_back=(ImageView)findViewById(R.id.img_back);
		tv_getting_ground=(TextView)findViewById(R.id.tv_getting_around);
		tv_red_money=(TextView)findViewById(R.id.red_money);
		img_tiyan=(TextView)findViewById(R.id.img_tiyan_money);
		tv_real_name=(TextView)findViewById(R.id.tv_real_name);
		btn_inassest=(Button)findViewById(R.id.in_assets);
//		btn_inreal_name=(Button)findViewById(R.id.in_realname);

		img_tiyan.setText(tiyan_money+"");
		
//		img_tiyan.setText("¥"+tiyan_money);
		tv_red_money.setText(tiyan_money+"");
//		tv_real_name.setText(resume_real_name+"元体验金");
		rl_back=(RelativeLayout)findViewById(R.id.rl_back);
		tv_getting_ground.setOnClickListener(this);
		rl_back.setOnClickListener(this);
		btn_inassest.setOnClickListener(this);
//		btn_inreal_name.setOnClickListener(this);
		img_back.setOnClickListener(this);
		
	}
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		BbtApplication.getInstance().removeActvity(this);
	}
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			if (who==3) {
				//return false;
				finish();
			}else {
				Intent intent = new Intent(this,MainActivity.class);
				startActivity(intent);
				finish();
				return super.onKeyDown(keyCode, event);
			}
		}
		return super.onKeyDown(keyCode, event);
	}
	private void test2(){
		VolleryUtil volleryUtil=new VolleryUtil() {
			
			@Override
			public void onUpDate(JSONObject jsonObject) {
				// TODO Auto-generated method stub
				Log.e("register_exp", jsonObject.toString());
				if(jsonObject.optInt("success")==1){
					Intent intent=new Intent(Register_Success.this,ExperienceGoldProduct.class);
					intent.putExtra("id", jsonObject.optString("data"));
					intent.putExtra("flag", 1);
					startActivity(intent);
					finish();
				}
			}
			
			@Override
			public void onError() {
				// TODO Auto-generated method stub
				
			}
		};
		volleryUtil.setHeaders("token", getToken());
		volleryUtil.setRequestMethod(1);
		volleryUtil.setShow(true);
		volleryUtil.execute(Register_Success.this, Constant.URL+"/api/v5/experience/getExpIdByExpType?expType=register", "");
	}
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch(v.getId()){
		case R.id.img_back:
			Intent intent=new Intent(Register_Success.this,MainActivity.class);
			intent.putExtra("regist", 0); 
			startActivity(intent);
		case R.id.in_assets:
			test2();
			
			break;
		case R.id.tv_getting_around:
			Intent intent4=new Intent(Register_Success.this,MainActivity.class);
			intent4.putExtra("regist", 0); 
			startActivity(intent4);
			break;
		case R.id.rl_back:
			Intent intent3=new Intent(Register_Success.this,MainActivity.class);
			startActivity(intent3);
			break;
			
		}
	}

}
